angular.module('fileModule.directives', [])  
  .directive('fileupload', function() {  
      return {  
        restrict:'A',  
        scope: {  
            done: '&',  
            progress: '&',
            add:'&',
            fail:'&'
        },  
        link: function(scope, element, attrs) {  
            var optionsObj = {  
               // dataType: 'json' 	
            	autoUpload: false
            	//,acceptFileTypes:  /(\.|\/)(gif|jpe?g|png)$/
            };  
            if(scope.done) { 
                optionsObj.done = function(e, data) {  
                    scope.$apply(function() {  
                        scope.done({e: e, data: data});  
                    });  
                };  
            }  
            if(scope.progress) {  
                optionsObj.progress = function(e, data) {  
                    scope.$apply(function() {  
                        scope.progress({e: e, data: data});  
                    });  
                };  
            }  
            if(scope.add){
            	optionsObj.add = function(e, data) {  
                    scope.$apply(function() {  
                        scope.add({e: e, data: data});  
                    });  
                }; 
            }
            if(scope.fail){
            	optionsObj.fail = function(e, data) {  
                    scope.$apply(function() {  
                        scope.fail({e: e, data: data});  
                    });  
                }; 
            }
            
            
            
            
            //以上内容可以简单地在一个循环中完成，这里是为了覆盖Fileupload控件所提供的API  
            element.fileupload(optionsObj);  
        }  
      };  
  });  